
#include "ttg/all.h"

using namespace ttg::services;
using namespace ttg::utils;
using namespace ttg::pipeline;

//Generates heavy subtasks, number of that is equal to input int.
class SampleNode :public Node<int, int>
{
	protected:
		virtual void process(int data)
		{
			if (data > 0)
			{
				for (int i = 0; i < data; i++)
					sendThis(-1);
			}
			else
			{
				volatile float f = 0.0f;
				for (size_t i = 0; i < 16 * 1024 * 1024; i++)
					f += sinf(TTG_PI / (16 * 1024) * i);
			}
		}
};

int main()
{
	Services services(true);
	Parameter<int> task_count("task_count");
	printf("Using ttgLib v%s\n", ttg::Version::toString());
	UtilManager::getRef()->activateWindow();
	Pipeline<int, int> pl(wrap(new SampleNode()));
	size_t core_count = CPUAnalyzer::getRef()->getCoreCount();
	while (true)
	{
		task_count = ttg::math::getIntRandom<int>(1, (int)core_count);
		printf("Core count %d...\n", (int)task_count);
		pl.run(task_count);
	}
}
